//
//  OAViewEffect.m
//  OpenAnimation
//
//  Created by Kieran Lafferty on 11-06-05.
//  Copyright 2011 Queen's University. All rights reserved.
//

#import "OAViewEffect.h"
#import <QuartzCore/QuartzCore.h>

@implementation OAViewEffect

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Simply move a view to a new position
//  Intended use: Shift window contents to any x, y coordinate
+(void) moveView: (UIView*) viewToMove toCenterPoint: (CGPoint) newCenter{
    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^(void) {
        [viewToMove setCenter:newCenter]; 
    } completion: nil];
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Swing and Drop animation to simulate a picture frame falling from the wall
//  Intended use: Password incorrect, or to dismiss popover view
+(void) frameSwingAndDrop: (UIView*) dropView willDropWithDuration:(NSInteger) duration{
    //1. set the anchor point to 1/4 x and 1/4 y to create off center hinge
    [dropView.layer setAnchorPoint:CGPointMake(dropView.frame.size.width/4, dropView.frame.size.height/4)];
    
    //2. create pendular effect. Swing left, right, then drop during mid left swing 
    
    //3. drop while rotating
    
    //4. present view again in original position by fade in
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Earthquake animation to simulate a shaking motion
//  Intended use: Password Incorrect. See Snow Leopard password incorrect animation
+(void) earthquake: (UIView*) dropView willDropWithDuration:(NSInteger) duration{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    [animation setDuration:0.05];
    [animation setRepeatCount:8];
    [animation setAutoreverses:YES];
    [animation setFromValue:[NSValue valueWithCGPoint:
                             CGPointMake([dropView center].x - 20.0f, [dropView center].y)]];
    [animation setToValue:[NSValue valueWithCGPoint:
                           CGPointMake([dropView center].x + 20.0f, [dropView center].y)]];
    [[dropView layer] addAnimation:animation forKey:@"position"];
}
@end
